package com.socket.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Controller;

import java.util.HashMap;
import java.util.Map;

@Controller
public class WebSocketController {

    @Autowired
    private SimpMessagingTemplate template;

    //广播推送消息
//    @Scheduled(fixedRate = 1000)
    public void sendTopicMessage() {
        System.out.println("后台广播推送！");
        Map<String, Object> map = new HashMap<>();
        map.put("name", "oyzc");
        map.put("age", 20);
        this.template.convertAndSend("/topic/getResponse", map);
    }
}

